package com.coin900.coin.service.coin;

import com.coin900.coin.base.utils.MailUtils;
import com.coin900.coin.persist.coin.CoinMailVerifyRecordVO;
import com.value.mybatis.IDaoRouter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Service
public class CoinMailVerifyRecordService implements ICoinMailVerifyRecordService {

    @Override
    public List<CoinMailVerifyRecordVO> loadCoinMailVerifyRecord(Map<String, Object> params) {
        return this.daoRouter.query("CoinMailVerifyRecord.loadCoinMailVerifyRecord", params);
    }

    @Override
    public void insertCoinMailVerifyRecord(CoinMailVerifyRecordVO coinMailVerifyRecordVO) throws IOException {
        String verifyToken = MailUtils.buildMailVerifyToken();
        coinMailVerifyRecordVO.setVerifyToken(verifyToken);
        this.daoRouter.insert("CoinMailVerifyRecord.insertCoinMailVerifyRecord", coinMailVerifyRecordVO);
        String message = "点击链接激活账号" +
                "http://" + "www.tokenok.co" + "/coin/activate_mail?verifyToken=" + verifyToken;
        String subject = "激活邮件";
        MailUtils.sendEmail(message, coinMailVerifyRecordVO.getMailBox(), subject);
    }

    @Override
    public void updateCoinMailVerifyRecord(CoinMailVerifyRecordVO coinMailVerifyRecordVO) {
        this.daoRouter.update("CoinMailVerifyRecord.updateCoinMailVerifyRecord", coinMailVerifyRecordVO);
    }

    @Override
    public void deleteCoinMailVerifyRecord(CoinMailVerifyRecordVO coinMailVerifyRecordVO) {
        this.daoRouter.update("CoinMailVerifyRecord.deleteCoinMailVerifyRecord", coinMailVerifyRecordVO);
    }

    @Autowired
    private IDaoRouter daoRouter;

}